﻿using ELTE.SEM.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
    public static class StringEx
    {
        public static SemDataParsedResult ParseSemData(this string str)
        {
            List<BaseSemData> TiffDataFields = new List<BaseSemData>();
            List<String> unknownRecords = new List<string>();
            try
            {

                string[] splitted = str.Split(new char[] { '[' }, StringSplitOptions.RemoveEmptyEntries);
                //a mezők neve az első "]" karaktering tart
                splitted.ToList().ForEach(entry =>
                {
                    int firstIndex = entry.IndexOf(']');
                    string name = entry.Substring(0, firstIndex);
                    string entryWithRemovedName = entry.Substring(firstIndex+1);
                    switch (name)
                    {
                        case "User":
                            TiffDataFields.Add(new SemUser(entryWithRemovedName));
                            break;
                        case "System":
                            TiffDataFields.Add(new SemSystem(entry));
                            break;
                        case "Beam":
                            TiffDataFields.Add(new SemBeam(entry));
                            break;
                        case "EBeam":
                            TiffDataFields.Add(new SemEBeam(entry));
                            break;
                        case "GIS":
                            TiffDataFields.Add(new SemGIS(entry));
                            break;
                        case "GIS1":
                            TiffDataFields.Add(new SemGIS1(entry));
                            break;
                        case "GIS2":
                            TiffDataFields.Add(new SemGIS2(entry));
                            break;
                        case "GIS3":
                            TiffDataFields.Add(new SemGIS3(entry));
                            break;
                        case "Scan":
                            TiffDataFields.Add(new SemScan(entry));
                            break;
                        case "EScan":
                            TiffDataFields.Add(new SemEScan(entry));
                            break;
                        case "Stage":
                            TiffDataFields.Add(new SemStage(entry));
                            break;
                        case "Image":
                            TiffDataFields.Add(new SemImage(entry));
                            break;
                        case "Vacuum":
                            TiffDataFields.Add(new SemVacuum(entry));
                            break;
                        case "Specimen":
                            TiffDataFields.Add(new SemSpecimen(entry));
                            break;
                        case "Detectors":
                            TiffDataFields.Add(new SemDetectors(entry));
                            break;
                        case "ETD":
                            TiffDataFields.Add(new SemETD(entry));
                            break;
                        case "Accessories":
                            TiffDataFields.Add(new SemAccessories(entry));
                            break;
                        case "EBeamDeceleration":
                            TiffDataFields.Add(new SemEBeamDeceleration(entry));
                            break;
                        case "PrivateFei":
                            TiffDataFields.Add(new SemPrivateFei(entry));
                            break;
                        case "QuadBSD":
                            TiffDataFields.Add(new SemQuadBSD(entry));
                            break;
                        case "GSED":
                            TiffDataFields.Add(new SemGSED(entry));
                            break;
                        case "vCD":
                            TiffDataFields.Add(new SemvCD(entry));
                            break;
                        case "CDEM":
                            TiffDataFields.Add(new SemCDEM(entry));
                            break;
                        case "LVSED":
                            TiffDataFields.Add(new SemLVSED(entry));
                            break;
                        case "IBeam":
                            TiffDataFields.Add(new SemIBeam(entry));
                            break;
                        case "IScan":
                            TiffDataFields.Add(new SemIScan(entry));
                            break;
                        case "BSED":
                            TiffDataFields.Add(new SemBSED(entry));
                            break;
                        case "STEM II":
                            TiffDataFields.Add(new SEMSTEM_II(entry));
                            break;
                        default:
                            //nem felismert név
                            //hozzá kell adni a nem felismert nevek listájához
                            unknownRecords.Add(entry);
                            break;

                    }
                });
            }
            catch (Exception ex)
            {
                
            }
            return new SemDataParsedResult { BaseSemData = TiffDataFields, UnknownRecords = unknownRecords };
        }
    }
}
